1
The Functional Paradigm: Transformation Over Mutation
AI019 Lesson 2
00:00

The functional paradigm shifts the developer's mental model from "updating a stateful box" to applying mathematical transformations to immutable values. In Elixir, data is never changed; it is only reborn into new forms.

1. The Mathematical Assertion

When you write $x = a + 1$, you are not assigning a result to a variable. Instead, you are simply asserting that the expressions $x$ and $a + 1$ have the same value. This mirrors algebraic logic where $x$ represents a fixed value in a specific context.

2. Immutability as a Guarantee

In Elixir, all values are immutable. Data cannot be altered once created. This eliminates "side effects" where a function might unexpectedly change a global variable or a passed-in object, ensuring that code is predictable and thread-safe.

BEFORE (Input)"elixir"String.capitalizeAFTER (Result)"Elixir"Original data remains unchanged

3. Transformation vs. Mutation

We never modify data in place. Elixir doesn't have assignment; instead, it tries to match values to patterns. To "change" a value, we pass the original data through a function to produce a completely new version.

iex> name = "elixir"
"elixir"
iex> cap_name = String.capitalize name
"Elixir"
iex> name
"elixir" (Still pristine!)
main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>